/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: ReflexTestController
 * Author:   pc
 * Date:     2019/9/23 14:19
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.example.rabbitmqdemo.controller;


import com.example.rabbitmqdemo.entity.Person;
import com.example.rabbitmqdemo.entity.UserInfo;
import com.example.rabbitmqdemo.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;


/**
 * 〈功能：〉<br>
 * 〈〉
 * @author liuhaoran
 * @create 2019/9/23 14:19
 * @since 1.0.0
 */
@Controller
public class ReflexTestController {
	/**
	 * 反射
	 * @return
	 */
	@ResponseBody
	@PostMapping("/senfreflx1")
	 public String sendReflex1(){
		Person person =new Person("张三", 18);
		Class clazz = person.getClass();
		Field[] fields = clazz.getDeclaredFields();
		for (Field field : fields) {
			String key = field.getName();
			try {
				PropertyDescriptor descriptor = new PropertyDescriptor(key, clazz);
				Method method = descriptor.getReadMethod();
				Object value = method.invoke(person);
				System.out.println(key + ":" + value);

			}catch (IntrospectionException e){
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} finally {
				System.out.println("待排查");
			}
		}
		return "success";
	}

}